// subcontract/Mine/addcard/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickname: '',//姓名
    name: '',//银行名称
    branch: '',//开户行
    mobile: '',//手机号
    account: '',//卡号
    columns: [],
    pickerShow: false,
  },
  async submit() {
    let { name, branch, nickname, mobile, account } = this.data
    if (this.data.type == 0) {
      let object = {
        agent_id: getApp().userinfo.agent_id,
        nickname,
        account,
        branch,
        mobile,
        name: name.bank_name || '',
        type: 0
      }
      console.log(object);
      const { code, msg } = await getApp().api.addBankCard(object)
      if (code == 1) {
        getApp().showToast(msg)
        setTimeout(() => {
          wx.navigateBack()
        }, 2000)
      }
    } else {
      let object = {
        agent_id: getApp().userinfo.agent_id,
        username: nickname,
        account,
      }
      console.log(object);
      const { code, msg } = await getApp().api.addAlipay(object)
      if (code == 1) {
        getApp().showToast(msg)
        setTimeout(() => {
          wx.navigateBack()
        }, 2000)
      }
    }

  },
  onChange(event) {
    console.log(event);
    const { picker, value, index } = event.detail;
    this.setData({ pickerShow: false, name: value });
  },
  onClose() {
    this.setData({ pickerShow: false });
  },
  openPicker() {
    this.setData({
      pickerShow: true
    })
  },
  /**银行列表 */
  async bankList() {
    const { code, data } = await getApp().api.bankList()
    if (code == 1) {
      this.setData({
        columns: data.list.map(item => {
          item.text = item.bank_name
          return item
        })
      })
    }
  },
  onChenginput(event) {
    let { type } = event.currentTarget.dataset
    let value = event.detail.value
    switch (type) {
      case '0':
        this.setData({ nickname: value })
        break;
      case '1':
        this.setData({ account: value })
        break;
      case '2':
        this.setData({ branch: value })
        break;
      case '3':
        this.setData({ mobile: value })
        break;
      case '4':
      // 如果没有任何case匹配时执行的代码
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      type: options.type
    })
    this.bankList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})